<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('新增订单信息')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>

<body class="white-bg">
    <div class="col-sm-12 search-collapse">
        <form id="formId">
            <div class="select-list">
                <ul>
                    <li>
                        <label>姓名：</label>
                        <input type="text" name="name" />
                    </li>
                    <li>
                        <label>手机号码：</label>
                        <input type="text" name="phone" />
                    </li>
                    <li>
                        <label>身份证号码：</label>
                        <input type="text" name="idcard" />
                    </li>
                    <input type="text" name="pageSize" value="1" hidden>
                    <input type="text" name="pageNum" value="1" hidden>
                    <input type="text" name="isAsc" value="1" hidden>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="getUser()"><i
                                class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <script>
        function getUser() {
            $.ajax({
                type: "POST",
                dataType: 'json',
                url: '/user/info/list',
                data: $('#formId').serialize(),
                success: function (data) {
                    if (data['rows'].length <= 0) {
                        alert("用户不存在");
                    } else {
                        $('#phoneNum').val(data['rows'][0]['phone']);
                    }

                },
                error: function (data) {
                    alert("error:" + data.responseText);
                }
            });
        }
    </script>
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-info-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">预订方式：</label>
                <div class="col-sm-8">
                    <input name="preOrderTypeId" class="form-control" type="text" required value="1" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">手机号：</label>
                <div class="col-sm-8">
                    <input name="phone" id="phoneNum" class="form-control" type="text" required readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">房间数：</label>
                <div class="col-sm-8">
                    <input name="numOfRoom" id="numOfRoom" class="form-control" type="text" required readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">入住人数：</label>
                <div class="col-sm-8">
                    <input name="peopleCount" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">预订日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="orderDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">预定天数：</label>
                <div class="col-sm-8">
                    <input name="orderDays" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">订单状态:</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('order_status')}">
                        <input type="radio" th:id="${'orderStatus_' + dict.dictCode}" name="orderStatus"
                            th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                        <label th:for="${'orderStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">订单费用：</label>
                <div class="col-sm-8">
                    <input name="orderCost" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">支付方式：</label>
                <div class="col-sm-8">
                    <select name="payType" class="form-control m-b" th:with="type=${@dict.getType('pay_type')}"
                        required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                        </option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "order/info"
        $("#form-info-add").validate({
            focusCleanup: true
        });
        (function(){
            var rows = localStorage.getItem('selectRoom').split(",");
            $('#numOfRoom').val(rows.length);
            for(var i in rows) $('#form-info-add').append(`<input type="text" name="rooms[${i}]" value="${rows[i]}" hidden>`);
        })();
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-info-add').serialize());
            }
        }

        $("input[name='orderDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>

</html>